package IOstreams;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.ResourceBundle;

public class ReadPropertiesTest {
    public static void main(String[] args) {
//        String path = Thread.currentThread().getContextClassLoader().getResource("IOstreams/jdbc.properties").getPath();路径中的绝对路径包含中文，报错
//        try (FileReader reader = new FileReader("ChapterLearning/src/jdbc.properties")) {
//            Properties properties = new Properties();
//            properties.load(reader);
//            String driver = properties.getProperty("jdbc.driver");
//            String url = properties.getProperty("jdbc.url");
//            String username = properties.getProperty("jdbc.username");
//            String password = properties.getProperty("jdbc.password");
//            String initialSize = properties.getProperty("jdbc.initialSize");
//            String maxActive = properties.getProperty("jdbc.maxActive");
//            String minIdle = properties.getProperty("jdbc.minIdle");
//            String maxWait = properties.getProperty("jdbc.maxWait");
//            System.out.println(driver);
//            System.out.println(url);
//            System.out.println(username);
//            System.out.println(password);
//            System.out.println(initialSize);
//            System.out.println(maxActive);
//            System.out.println(minIdle);
//            System.out.println(maxWait);
//
//        } catch (FileNotFoundException e) {
//            throw new RuntimeException(e);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        ResourceBundle resourceBundle = ResourceBundle.getBundle("jdbc");
        String username = resourceBundle.getString("jdbc.username");
        String url = resourceBundle.getString("jdbc.url");
        System.out.println(username);
        System.out.println(url);
    }
}
